<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="com.dao.Users"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改用户</title>
<script type="text/javascript">
/*账号确认*/
function judge1(){
		var user=document.getElementById("user");
		var text=document.getElementById("text");
		var text2=document.getElementById("text2");
		text.style.display="none";
		text2.style.display="none";
	}
function judge2(){
	var user=document.getElementById("user");
	var text=document.getElementById("text");
	var text2=document.getElementById("text2");
		if(user.value==""){
			text.style.display="block";
			text2.style.display="none";
		}else if(user.value!=""){
			var xhr =new XMLHttpRequest();
			xhr.open("GET","${pageContext.request.contextPath}/UsersServlet?submittype=getuser&user="+user.value);
			xhr.send();
			xhr.onreadystatechange=function(){
				if(xhr.readyState==4){
					if(xhr.status==200){
						if(xhr.responseText=="true"){
							text.style.display="none";
							text2.style.display="block";
						}else{
							text.style.display="none";
							text2.style.display="none";
						}
					}
				}
			}
		}else{
			 alert("失败了");
		}
	}

/*昵称确认*/
function judge3(){
		var user=document.getElementById("user2");
		var text1=document.getElementById("text1");
		text.style.display="none";
	}
function judge4(){
	var user=document.getElementById("user2");
	var text=document.getElementById("text1");
		if(user.value==""){
			text.style.display="block";
		}else{
			text.style.display="none";
		}
		
	}
	
/*输入密码确认*/
function judge5(){
		var psw=document.getElementById("psw");
		var text3=document.getElementById("text3");
		var text4=document.getElementById("text4");
		text3.style.display="none";
		text4.style.display="none";
	}
function judge6(){
	var psw=document.getElementById("psw").value;
	var text3=document.getElementById("text3");
	var text4=document.getElementById("text4");
		if(psw==""){
			text3.style.display="block";
			text4.style.display="none";
		}else if(psw.length<6||psw.length>10){
			text3.style.display="none";
			text4.style.display="block";
		}else{
			text3.style.display="none";
			text4.style.display="none";
		}
	}

/*再次输入密码确认*/	
function judge7(){
		var psw2=document.getElementById("psw2");
		var text5=document.getElementById("text5");
		var text6=document.getElementById("text6");
		text5.style.display="none";
		text6.style.display="none";
	}
function judge8(){
	var psw2=document.getElementById("psw2").value;
	var psw=document.getElementById("psw").value;
	var text5=document.getElementById("text5");
	var text6=document.getElementById("text6");
		if(psw2==""){
			text5.style.display="block";
			text6.style.display="none";
		}else if(psw2!=psw){
			text5.style.display="none";
			text6.style.display="block";
		}else{
			text5.style.display="none";
			text6.style.display="none";
		}
	}
</script>
</head>
<body>
<c:set var="obj" value="${sessionScope.UserMessage}"/>
<c:set var="id" value="${param.id}"/>
<c:set var="username" value="${param.username}"/>
<c:set var="nickname" value="${param.nickname}"/>
<c:set var="password" value="${param.password}"/>
<div style=" height:300px; line-height:63px" align="center" >
		<h1>修改用户</h1>
		<form action="${pageContext.request.contextPath}/UsersServlet" method="post">
		<input name="id" type="hidden" value="${id}">
		<c:choose>
		<c:when test="${obj.man_id==1}">
		<table width="600px">
		<tr>
	    <td align="right">用户名：</td>
	    <td width="150px" align="left"><input name="username" type="text" value="${username}" id="user" onfocus="judge1(this)" onblur="judge2(this)"/></td>
	    <td width="270px" align="left"><em id="text" style="display:none;">账号不能为空！</em>
	    	<em id="text2" style="display:none;">账号重复！</em></td>
		</tr>
		<tr>
	    <td align="right">昵称：</td>
	    <td width="150px" align="left"><input name="nickname" type="text" value="${nickname}" id="user2" onfocus="judge3(this)" onblur="judge4(this)"/></td>
	    <td width="270px" align="left"><em id="text1" style="display:none;">昵称不能为空！</em></td>
	  	</tr>
	  	 <tr>
	    <td align="right">密码：</td>
	    <td width="150px" align="left"><input name="password" type="password" value="${password}" id="psw" onfocus="judge5(this)" onblur="judge6(this)"/></td>
	    <td align="left"><em id="text3" style="display:none;">密码不能为空！</em>
			<em id="text4" style="display:none;">密码不能少于六位且不能大于十位！</em></td>
	  	</tr>
	  	<tr>
	    <td align="right">再次输入密码：</td>
	    <td width="150px" align="left"><input name="password" type="password" value="" id="psw2" onfocus="judge7(this)" onblur="judge8(this)"/></td>
	    <td align="left"><em id="text5" style="display:none;">密码不能为空！</em>
			<em id="text6" style="display:none;">两次输入不一致！</em></td>
	  	</tr>
		</table>
		</c:when>
		<c:otherwise>
			当前登录用户：${username}<br>
			<input name="username" type="hidden" value="${username}">
			用户昵称：<input name="nickname" type="text" value="${nickname}"><br> 
			用户密码：<input name="password" type="text" value="${password}"><br>
		</c:otherwise>
		</c:choose>
  	  		<input name="submittype" type="submit" value="修改当前用户"/> 
			<input type="reset" name="submittype" value="重置">
  	   </form>
  	   <form action="control.jsp" method="post">
			<input name="submittype" type="submit" value="返回"/>
  	   </form>
  	   <td>${error}</td>
	</div>
</body>
</html>